package com.platform.modules.sys.controller;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.cxf.endpoint.Client;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
//import org.apache.cxf.endpoint.Client;
//import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.crypto.hash.Sha256Hash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.platform.common.annotation.SysLog;
import com.platform.common.page.PageUtil;
import com.platform.common.utils.Constant;
import com.platform.common.utils.Query;
import com.platform.common.utils.RestResponse;
import com.platform.common.validator.AbstractAssert;
import com.platform.common.validator.ValidatorUtils;
import com.platform.common.validator.group.AddGroup;
import com.platform.common.validator.group.UpdateGroup;
import com.platform.common.enumstatus.AptitudeEnum;
import com.platform.common.enumstatus.SystemEnum;
import com.platform.modules.sys.entity.SysOrgEntity;
import com.platform.modules.sys.entity.SysOrgUserEntity;
import com.platform.modules.sys.entity.SysRoleEntity;
import com.platform.modules.sys.entity.SysUserAptitudeEntity;
import com.platform.modules.sys.entity.SysUserEntity;
import com.platform.modules.sys.form.PasswordForm;
import com.platform.modules.sys.service.SysDictService;
import com.platform.modules.sys.service.SysOrgService;
import com.platform.modules.sys.service.SysOrgUserService;
import com.platform.modules.sys.service.SysRoleService;
import com.platform.modules.sys.service.SysUserAptitudeService;
import com.platform.modules.sys.service.SysUserRoleService;
import com.platform.modules.sys.service.SysUserService;

/**
 * 系统用户  
 *           
 * @author 肖亮
 */
@RestController
@RequestMapping("/sys/sendMessage")
public class SysWeChatSendMessageController extends AbstractController {
	@Autowired
	private SysUserService sysUserService;
	@Autowired
	private SysOrgUserService sysOrgUserService;
	@Autowired
	private SysUserRoleService sysUserRoleService;
	@Autowired
	private SysRoleService sysRoleService;
	@Autowired
	private SysOrgService sysOrgService;
	@Autowired
	private SysUserAptitudeService sysUserAptitudeService;
	@Autowired
	private SysDictService sysDictService;
	

	/**
	 * 查看所有列表
	 * @param params
	 * @return RestResponse
	 */
	@ApiOperation(value = "微信推送", notes = "微信推送")
	@ApiImplicitParams({
	@ApiImplicitParam(paramType = "query", name = "wechatUserId", value = "注册人员Id", dataType = "String"),
	@ApiImplicitParam(paramType = "query", name = "orgNo", value = "机构编码", dataType = "String")
	})
	@PostMapping("/sendMessage")
	public RestResponse sendMessage(String wechatUserId,String orgNo) {
		
			//objs1 推送结果	1代表推送消息成功0代表推送消息失败	 
			String objs1 = "";
			//result 显示查询人员结果 1从对方服务器查询人员成功0代表从对方服务器查询人员失败
			String result;
			try {
			    JaxWsDynamicClientFactory factory = JaxWsDynamicClientFactory.newInstance();
			    String url = "https://wx.xiaolingjituan.cn:8443/jeewx/services/WeiXinWebservice?wsdl";
			    Client client = factory.createClient(url);
		  		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		  		JSONObject per = new JSONObject();
		  		JSONArray arr = new JSONArray();

			if("" != null){
				System.out.println("查询人员无问题===="+wechatUserId);

					per.put("send_id".toUpperCase(), "");
					per.put("open_id".toUpperCase(),"otPN2uPkF_HCjEFMgX4Grrxsppr4");
					per.put("temp_id".toUpperCase(), "2003");
					per.put("temp_from".toUpperCase(), "7");
					per.put("staff_id".toUpperCase(), "");
					per.put("dwgc_id".toUpperCase(), "");
					per.put("dwgc_code".toUpperCase(), "");
					per.put("dwgc_name".toUpperCase(), "测试测试");
					per.put("stem_from".toUpperCase(), "7");//兵团系统指定的是2
					per.put("accept_no".toUpperCase(), "");
					per.put("sendtime".toUpperCase(), format.format(new Date()));
					per.put("exam_expert_type".toUpperCase(), "");
					per.put("send_state".toUpperCase(), "0");
					per.put("check_classes".toUpperCase(), "");
					per.put("check_prof".toUpperCase(), "");
					arr.add(per);
					Object[] obj = client.invoke("SendMessageInfo", new Object[] { arr.toString() });
					objs1 = (String)obj[0];
					if (objs1.equals("1")) {

					} else if (objs1.equals("0")) {

					}
				}
			}catch (Exception e) {
				e.printStackTrace();
			}
	
	
		return RestResponse.success();
	}

	
}
